<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:doc="livcos.org/ns/doc"
  xmlns="http://www.w3.org/1999/XSL/Format"
  exclude-result-prefixes="doc">
	
	<xsl:import href="../../../../base.xsl"/>

  <xsl:template match="doc:table">
		<block xsl:use-attribute-sets="block">
			<table table-layout="fixed" width="100%">
				<xsl:variable name="numCols" select="count(doc:body/doc:row[1]/doc:cell)"/>
				<xsl:apply-templates select="doc:body/doc:row[1]/doc:cell" mode="columnDecl"/>
				<xsl:if test="(normalize-space(doc:title) != '') or doc:head/doc:row">
					<table-header font-weight="bold" background-color="#EEEEEE">
						<xsl:if test="normalize-space(doc:title) != ''">
							<table-row>
								<table-cell number-columns-spanned="{$numCols}" border-style="solid" border-width="thin" padding="2pt">
									<block margin-left="0pt" text-align="center">
										<xsl:value-of select="doc:title"/>
									</block>
								</table-cell>
							</table-row>
						</xsl:if>
						<xsl:apply-templates select="doc:head/doc:row"/>
					</table-header>
				</xsl:if>
				<xsl:if test="doc:foot/doc:row">
					<table-footer>
						<xsl:apply-templates select="doc:foot/doc:row"/>
					</table-footer>
				</xsl:if>
				<table-body>
					<xsl:apply-templates select="doc:body/doc:row"/>
				</table-body>
			</table>
			<xsl:if test="normalize-space(doc:note) != ''">
				<block font-size="6pt" margin-left="1mm" margin-top="1mm">
					<xsl:apply-templates select="doc:note/node()"/>
				</block>
			</xsl:if>
		</block>
  </xsl:template>
  
  <xsl:template match="doc:cell" mode="columnDecl">
    <table-column column-width="{100 div count(../doc:cell)}%"/>
  </xsl:template>
  
  <xsl:template match="doc:row">
    <table-row>
      <xsl:apply-templates/>
    </table-row>
  </xsl:template>
  
  <xsl:template match="doc:cell">
    <table-cell padding="2pt" border-style="solid" border-width="thin">
      <xsl:if test="@colspan &gt; 1">
        <xsl:attribute name="number-columns-spanned">
          <xsl:value-of select="@colspan" />
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@rowspan &gt; 1">
        <xsl:attribute name="number-rows-spanned">
          <xsl:value-of select="@rowspan" />
        </xsl:attribute>
      </xsl:if>
      <block margin-left="-0.6cm">
      	<xsl:apply-templates select="node()"/>
      </block>
    </table-cell>
  </xsl:template>

</xsl:stylesheet>
